<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

  <th:block th:include="MainInterface/include :: common-css" />

</head>
<body class="fixed-left">
<div id="wrapper">

  <th:block th:include="MainInterface/include :: header-menu(4)" />

  <div class="content-page">
      <div class="content">
          <div class="container">
              <div class="row" id="all">
                  <div class="col-sm-12">
                      <h1 class="page-title">出版社管理</h1>
                  </div>
                  <div class="col-md-12">
                  <table class="table table-striped table-bordered">
                    <tr>
                      <th>id</th>
                      <th>出版社</th>
                      <th>操作</th>
                    </tr>
                    <tr th:each="publisherList:${publisherList}">
                      <td th:text="${publisherList.id}"></td>
                      <td th:text="${publisherList.name}"></td>
                      <td>
                      <a th:href="${'/publishe/edit'+publisherList.id}"
                          class="btn btn-primary btn-sm waves-effect waves-light m-b-5">
                          <i class="fa fa-edit"></i> <span>编辑</span></a>
                      <a href="javascript:void(0)" th:onclick="'delPublishe('+${publisherList.id}+')'"
                          class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                          <i class="fa fa-trash-o"></i> <span>删除</span></a>
                      </td>
                    </tr>
                  </table>
                  </div>
                  <button class="btn btn-primary btn-sm waves-effect waves-light m-b-5" style="background-color:rgb(133,250,133);color: black" onclick="add()">新增数据</button>
          </div>
              <!--添加数据-->
              <div id="add" style="display: none">

                  <div class="dialog">
                      <h1>添加出版社</h1>
                  <form id="bookList">
                      <div class="dialog-box">
                          <p>
                              出版社 : <input name="name">
                          </p>
                          <div>
                          <input style="width: 75px ; height : 50px " type="button" id="book_save" onclick="publisherAdd()" name="提交" value="提交">
                          <!--      <button id="book_save" onclick="publisherAdd()">提交</button>-->
                          <button style="width: 75px ; height : 50px "><a href="/publisher">返回</a></button>
                          </div>
                      </div>

                  </form>
              </div>
      </div>

  </div>
</div>
<th:block th:include="MainInterface/include :: foter" />
<th:block th:include="MainInterface/include :: common-js" />
<script>
  function delPublishe(id){
    if(confirm('确定删除该数据吗?')){
      $.ajax({
        type:"post",
        url:"/publisher/delete",
        data:{id:id},
        dataType: 'json',
        success:function (result) {
          if(result.code==0){
            window.alert("删除成功");
            window.location.reload();
          } else {
            window.alert(result.msg || "删除失败");
          }

        }
      });
    }

  }
  function publisherAdd(){
      $("#add").show();
      $.ajax({
          type:"post",
          url:"/publisher/saveOrUpdata",
          data:$("#bookList").serialize(),
          async:false,
          dataType: 'json',
          success:function (result) {
              // console.log($("#bookList").serialize(),)
              if(result.code==0){
                  window.alert("添加成功");
                  window.location.href="/publisher"
              } else {
                  window.alert(result.msg || "添加失败");
              }

          }
      });
  }
  function add(){
      $("#add").show();
      $("#all").hide();
  }
</script>
</body>
<style>
  .id{
    position: relative;
    cursor: pointer;
    display: inline-block;
    overflow: hidden;
  }
  table td {
    font-size: 12px;
    padding: 10px 30px;

    border-bottom: 1px solid #999;

    border-right: 1px solid #999;
  }
  table {
    border-top: 1px solid #999;

    border-left: 1px solid #999;

    border-spacing: 0;/*去掉单元格间隙*/

  }

</style>
</html>
